package com.sj.szxy.courseschedule.constrant;

import java.util.HashSet;
import java.util.Set;

import com.sj.szxy.courseschedule.entity.Teacher;
import com.sj.szxy.courseschedule.entity.course.Course;

/**
 * 
 * @author Yi Ping
 * @date 2018年3月29日 上午10:51:55 
 * @since 1.0.0
 *
 */
public class ExcludeTeacherConstraint extends Constraint  {

	private Set<Teacher> excludeTeachers = new HashSet<>();	
	
	public ExcludeTeacherConstraint() {
		
	}
	
	/**
	 * @param excludeTeachers
	 */
	public ExcludeTeacherConstraint(Set<Teacher> excludeTeachers) {
		super();
		this.excludeTeachers.addAll(excludeTeachers);
	}

	@Override
	public boolean support(Course course) {
		return !excludeTeachers.containsAll(course.getTeachers());
	}

	@Override
	public Constraint addConstraint(Constraint newConstraint) {
		if(newConstraint instanceof ExcludeTeacherConstraint) {
			this.excludeTeachers.addAll(((ExcludeTeacherConstraint) newConstraint).getExcludeTeachers());
			return this;
		}
		
		return super.addConstraint(newConstraint);
	}

	public Set<Teacher> getExcludeTeachers() {
		return excludeTeachers;
	}

	@Override
	public String toString() {
		return this.getClass().getSimpleName() + "@" +  excludeTeachers;
	}

	
}
